<include file="Common:layout" />
<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default;">
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>商品分类管理</h3>
            </div>
        </div>
    </div>
    <form method="post">
        <input type="hidden" value="ok" name="form_submit">
        <div class="flexigrid">

            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0">
                        <thead>
                        <tr>
                            <th align="center" axis="col1"><div style="text-align: center; width:60px;">操作</div></th>
                            <th align="center" axis="col2"><div style="text-align: center; width: 60px;">分类ID</div></th>
                            <th align="center" axis="col3"><div style="text-align: center; width: 200px;">分类名称</div></th>
                            <th align="center" axis="col6"><div style="text-align: center; width: 80px;">是否显示</div></th>
                            <th align="center" axis="col9"><div style="text-align: center; width: 60px;">排序</div></th>
                            <th axis="col10"><div></div></th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="tDiv">
                <div class="tDiv2">
                    <a href="{:U('Category/add_cate')}">
                        <div class="fbutton">
                            <div title="新增分类" class="add">
                                <span><i class="fa fa-plus"></i>新增分类</span>
                            </div>
                        </div>
                    </a>
                </div>
                <div style="clear:both"></div>
            </div>
            <div style="height: auto;" class="bDiv">
                <table cellspacing="0" cellpadding="0" border="0" id="article_cat_table" class="flex-table autoht">
                    <tbody id="treet1">
                    <foreach name="categories" item="vo" key="k" >
                        <tr class="parent_id_{$vo.pid}" <if condition="$vo[level] gt 1"> style="display:none;"</if>>
                        <td class="sign">
                            <if condition="$vo[level] lt 3">
                                <!--<div style="text-align: center; width: 24px;">
                                    <img onClick="treeClicked(this,{$vo.id},'{$vo.parent_id_path}')" nc_type="flex" status="open" fieldid="2" src="__PUBLIC__/images/tv-expandable.gif">
                                </div>-->
                            </if>
                        </td>
                        <td class="handle" <if condition="$vo[level] eq 2">style="padding-left:40px;"<elseif condition="$vo[level] eq 3"/>style="padding-left:70px;"<else/></if>>
                            <div style="text-align:left;min-width:50px!important; max-width:inherit !important;">
                                <a href="{:U('Category/edit',array('id'=>$vo['id']))}" class="btn blue"><i class="fa fa-edit"></i>编辑</a>
                            </div>
                        </td>
                        <td class="sort">
                            <div style="text-align: center; width: 60px;">{$vo.id}</div>
                        </td>
                        <td class="name">
                            <div style="text-align: center; width: 200px;">
                            {$vo.c_name}
                            </div>
                        </td>
                        <td align="center" class="">
                            <div style="text-align: center; width: 80px;">
                                <if condition='$vo[status] eq 1'>
                                    <span class="yes" onClick="changeTableVal('category','id','{$vo.id}','status',this)"><i class="fa fa-check-circle"></i>是</span>
                                    <else />
                                    <span class="no" onClick="changeTableVal('category','id','{$vo.id}','status',this)"><i class="fa fa-ban"></i>否</span>
                                </if>
                            </div>
                        </td>
                        <td class="sort">
                            <div style="text-align: center; width: 60px;">
                                <input type="text" onKeyUp="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onchange="changeTableVal('category','id','{$vo.id}','sort',this)" size="4" value="{$vo.sort}" />
                            </div>
                        </td>
                        <td style="width: 100%;">
                            <div>&nbsp;</div>
                        </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
                <br/>
            </div>
        </div>
    </form>
</div>
<script>
    $(document).ready(function(){
        $('.del_cate').click(function () {
            var _this = $(this);
            layer.confirm('您确认删除此分类吗？', {
                btn: ['确认','取消']
            }, function(){
                $.ajax({
                    url: "{:U('Category/del')}",
                    type: "post",
                    data: {
                        id: _this.attr('data-id')
                    },
                    beforeSend: function () {
                        layer.msg('删除分类中..', {icon: 16,time:500});
                    },
                    success: function (msg) {

                        if (msg == -1) {
                            layer.msg('请先删除子类!', {icon: 8,time:1000});
                        } else if(msg == -2) {
                            layer.msg('此分类被商品占用，请先删除商品!', {icon: 8,time:1000});
                        } else if(msg == 1) {
                            window.location.href = "{:U('Category/index')}"
                        } else {
                            layer.msg('删除失败!', {icon: 2,time:1000});
                        }
                    }
                });
            });
        });
    });

    // 点击展开 收缩节点
    function treeClicked(obj,cat_id)
    {
        var src = $(obj).attr('src');
        if(src == '__PUBLIC__/images/tv-expandable.gif')
        {
            $(".parent_id_"+cat_id).show();
            $(obj).attr('src','__PUBLIC__/images/tv-collapsable-last.gif');
        }else{
            $(".parent_id_"+cat_id).hide().find('img').attr('src','__PUBLIC__/images/tv-expandable.gif');
            $(obj).attr('src','__PUBLIC__/images/tv-expandable.gif');
        }
    }
</script>
</body>
</html>